package com.zzj.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzj.bean.DeptBean;
import com.zzj.dao.DeptDao;
import com.zzj.service.DeptService;
import com.zzj.utils.Result;
import com.zzj.utils.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

import static java.awt.SystemColor.info;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptDao deptDao;

    /**
     * 增加一个部门
     * @param deptBean
     * @return 改变的行数
     */
    @Override
    public Result addDept(DeptBean deptBean) {
        int i = deptDao.addDept(deptBean);
        if (i==1){
            return new Result(true, StatusCode.OK,"添加成功");
        }
        return new Result(false,StatusCode.ERROR,"添加失败");
    }

    /**修改一个部门信息
     * @param deptBean
     * @return 改变的行数
     */
    @Override
    public Result updateDept(DeptBean deptBean) {
        int i = deptDao.updateDeptByDid(deptBean);
        if(i==1){
            return new Result(true,StatusCode.OK,"修改成功");
        }
        return new Result(false,StatusCode.ERROR,"修改失败");
    }

    /**
     * 查询所有部门信息
     * @param
     * @param
     * @return
     */
    @Override
    public Result<List<DeptBean>> findAllDept() {
        List<DeptBean> allDept = deptDao.findAllDept();
        if (allDept!=null){
            return new Result<>(true,StatusCode.OK,"查询成功",allDept);
        }
        return new Result<>(false,StatusCode.ERROR,"列表为空");
    }

    /**
     * 通过部门ID查询部门信息
     * @param did
     * @return
     */
    @Override
    public Result<DeptBean> findDeptByDid(int did) {
        DeptBean deptByDid = deptDao.findDeptByDid(did);
        if (deptByDid!=null){
            return new Result<>(true,StatusCode.OK,"查询成功",deptByDid);
        }
        return new Result<>(false,StatusCode.ERROR,"查询失败，请重试");
    }
}
